/**
 * Created by wangmeng on 2018/3/29.
 */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const proxy = require('http-proxy-middleware');

module.exports = {

    devServer: {
        //开启IP访问
        contentBase: path.resolve(__dirname, "public"),
        historyApiFallback: true,
        disableHostCheck: true,
        port: 4000,
        publicPath: '/',
        inline: true,
        proxy: {
            '/api/*': {
                target: 'http://localhost:8080/',
                changeOrigin: true,
                secure: false,
                pathRewrite: {
                    "^/api": "/"
                }
            }
        }
    },
    entry: {
        bundle: './src/index.js',
    },
    devtool: 'inline-source-map', //只能用这个
    // devtool: 'false',
    output: {
        path: path.resolve(__dirname, "/public/"),
        filename: "bundle.js",
        //防止在子路径下刷新找不到js
        publicPath: "/"
    },
    module: {
        rules: [
            {
                test: /\.svg$/,
                use: [
                    {
                        loader: 'react-svg-loader',
                        options: {
                            es5: true,
                            svgo: {
                                plugins: [{
                                    removeAttrs: {attrs: 'xmlns.*'}
                                }]
                            }
                        }
                    }
                ]
            },
            {
                test: /\.less$/,
                use: [{
                    loader: "style-loader" // creates style nodes from JS strings
                }, {
                    loader: "css-loader" // translates CSS into CommonJS
                }, {
                    loader: "less-loader",
                    options: {javascriptEnabled: true}

                }],
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
            {
                test: /\.js?$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: [
                            "env",
                            "react",
                            "stage-0"
                        ],
                        plugins: [["import", {"libraryName": "antd", "style": false}]]
                    }
                }

            }
        ]
    },
    plugins: [

        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, './src/index.html'),
            inject: true
        })
    ]

};
